import { Component, OnInit,Input,Output,Host,Inject,forwardRef,EventEmitter } from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import {DragdropService} from '../../services/dragdrop.service'


@Component({
    selector: 'app-funnel',
    templateUrl: './funnel.component.html',
    styleUrls: ['./funnel.component.css']
})

export class FunnelComponent implements OnInit{

    curWidget={
        config:{
            values:[
                {cols:[]}
            ],
            chart_type:'table'
        }
    }
    dragEl=false
    
    constructor(
        public translate:TranslateService,
        private dragdropservice:DragdropService
    ) { 
        translate.addLangs(['zh','en']);                          //添加语言支持
        translate.setDefaultLang('en');                           //设置默认语言
        let broswerLang = translate.getBrowserLang();              //获取浏览器支持的语言
        console.log(broswerLang)                                   //zh
        translate.use(broswerLang.match(/zh|en/) ? broswerLang : 'en');
    }

    @Input() chartType:any;
    @Output() funnel=new EventEmitter<any>()
    ngOnInit(){

    }

    editExp(item){}

    editVFilter(item){}

    findIndex(el:any) {
        let index = -1;
        for(let i = 0; i < this.curWidget.config.values[0].cols.length; i++) {
            if(el.vin === this.curWidget.config.values[0].cols[i].vin) {
                index = i;
                break;
            }
        }
        return index;
      }
    measuredroped(){
        let t=this.dragdropservice.getmeasuredrag()
        console.log(t)
        this.curWidget.config.values[0].cols = [...this.curWidget.config.values[0].cols,t.a._events[0]]

        this.funnel.emit(this.curWidget.config.values[0].cols)
    }
}